import java.util.ArrayList;
import java.util.Random;

/*
* Creates RandomEvents and populates the map with RandomEvents.
* @author Jeoffrey Spinoza
* @version 1.0 31 October 2011
*/
public class RandomEventGenerator
{

    Random rand; 
    private Map map;
	private MainCardPanel display;
	private static final double JEEP_FREQ = .01; 
	private static final double RAIN_FREQ = .02;
	private static final double STORM_FREQ = .01; 
	private static final double WIRE_FREQ = .04;
	private static final double ENCOUNTER_FREQ = .01;
    private int mapSize;
    private Party party;
    /*
    * Creates a RandomEventGenerator to populate the given map.
    */
    public RandomEventGenerator(Map map, MainCardPanel display, Party party)
    {
        this.map = map;
        rand = new Random();
        this.display = display;
        mapSize = map.getLocationList().size();
        this.party = party;
       
    }

    /*
    private void maybeCreateEvent(Location loc)
    {
        if (rand.nextInt(EventProbability.denominator()) < odds)
            loc.addRandomEvent(new RandomEvent());
        return null;
    }
    */
    
    /*
    * Makes the RandomEventGenerator populate its map with RandomEvents according
    * to the probabilities given.
    * @param odds How much the default odds will be multiplied by.
    */
    public boolean populateMap(double landmarkOdds, double pathOdds)
    {
        
        ArrayList<Fields> fields = map.getFields();
        fields.get(rand.nextInt(fields.size())).addRandomEvent(new Encounter(display, party));
        for (Location loc:map.getLocations()) {
        	if (!loc.isFirstLocation())
        	{
	        	if (loc instanceof City)
	        		addRandomEvents((City) loc, landmarkOdds);
	        	
	        	else
	        		addRandomEvents((Fields) loc, pathOdds);
        	}
        	
        }
            
        return true;
    }
    
    private void addRandomEvents(Fields loc, double pathOdds) {
		if (rand.nextDouble() < JEEP_FREQ*pathOdds)
			loc.addRandomEvent(new Jeep(display, party));
		if (rand.nextDouble() < STORM_FREQ*pathOdds)
			loc.addRandomEvent(new Storm(display, party));
		if (rand.nextDouble() < RAIN_FREQ*pathOdds)
			loc.addRandomEvent(new Rain(display, party));
		if (rand.nextDouble() < ENCOUNTER_FREQ*pathOdds)
			loc.addRandomEvent(new Encounter(display, party));
		if (rand.nextDouble() < WIRE_FREQ*pathOdds)
			loc.addRandomEvent(new BarbedWire(display, party));
		
	}

	private void addRandomEvents(City loc, double landmarkOdds) {
		if (rand.nextDouble() < JEEP_FREQ*landmarkOdds)
			loc.addRandomEvent(new Jeep(display, party));
		if (rand.nextDouble() < STORM_FREQ*landmarkOdds)
			loc.addRandomEvent(new Storm(display, party));
		if (rand.nextDouble() < RAIN_FREQ*landmarkOdds)
			loc.addRandomEvent(new Rain(display, party));
		
	}
        
                    
                    
            
    
    


}